/*
 * @Author: czy
 * @Date: 2021-05-21 22:11:57
 * @LastEditTime: 2021-06-01 08:41:20
 */
#ifndef __STDARG_H_
#define __STDARG_H_

// typedef __builtin_va_list va_list;
// #define va_start(v, l) __builtin_va_start(v, l)
// #define va_end(v) __builtin_va_end(v)
// #define va_arg(v, l) __builtin_va_arg(v, l)
#ifndef va_start
typedef char *va_list;
#define va_start(AP, LASTARG) \
    (AP = ((char *)&(LASTARG) + __va_rounded_size(LASTARG)))
#define va_arg(AP, TYPE)            \
    (AP += __va_rounded_size(TYPE), \
     *((TYPE *)(AP - __va_rounded_size(TYPE))))
#define __va_rounded_size(TYPE) \
    (((sizeof(TYPE) + sizeof(int) - 1) / sizeof(int)) * sizeof(int))
#define va_end(AP)
#endif
#define va_arg_by_size(AP, SIZE) \
    (AP += __va_rounded(SIZE), (void *)(AP - __va_rounded(SIZE)))
#define __va_rounded(SIZE) \
    (((SIZE + sizeof(int) - 1) / sizeof(int)) * sizeof(int))

#endif